package com.example.demo.common;

import lombok.Data;

/**
 * JDK8兼容的API响应结果类
 */
@Data
public class ApiResult<T> {
    private int code;
    private String message;
    private T data;

    public ApiResult() {
    }

    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> success() {
        return new ApiResult<T>(0, "success", null);
    }

    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<T>(0, "success", data);
    }

    public static <T> ApiResult<T> error(String message) {
        return new ApiResult<T>(-1, message, null);
    }

    public static <T> ApiResult<T> error(int code, String message) {
        return new ApiResult<T>(code, message, null);
    }
}